


<?php 
$path = '../Mkart/';
include_once($path ."common.php");

//$key = $_GET['key'] ;
//$id = $_GET['id'] ;

$key = $_POST['key'];





for($m = 0 ; $m < count($_POST['id']) ; $m++){

$id = $_POST['id'][$m] ;
$word = $_POST['key'] ."=".$_POST['id'][$m] ;

$sql_op_C = "select * from product where id = '$id' order by id" ;
$result_op_C = mysql_query($sql_op_C) ;
$row_op_C = mysql_fetch_object($result_op_C) ;
$pd_name = $row_op_C -> name ;
$op_C01 = $row_op_C -> price_1 ;
$op_C02 = $row_op_C -> price_2 ;
$op_C03 = $row_op_C -> pd_count ;

$sql_rate = "select three_rate,six_rate,twelve_rate,tf_rate from stage " ;
$result_rate = mysql_query($sql_rate);
$row_rate=mysql_fetch_object($result_rate) ;
$rate_1 = $row_rate->three_rate ;
$rate_2 = $row_rate->six_rate ;
$rate_3 = $row_rate->twelve_rate ;
$rate_4 = $row_rate->tf_rate ;

$pric_rate3 = $op_C02 * (($rate_1+100)/100) ;
$pric_rate6 = $op_C02 * (($rate_2+100)/100) ;
$pric_rate12 = $op_C02 * (($rate_3+100)/100) ;
$pric_rate24 = $op_C02 * (($rate_4+100)/100) ;


if($op_C03 > 0){
	$button = "<input id=$id class=\"joincar\" type=\"button\" value=\"加入購物車\" onclick=\"chkkart('$id');alert('已新增 $pd_name 至購物車');\" >" ;
}else{
	$button = "<input id=$id class=\"joincar\" disabled type=\"button\" value=\"已售完補貨中\" >" ;
}

$kart_table = "<div id='kart_table'></div>" ;

switch($key){
	case 'price1':
	$res[$m] = array('price' => "$".$op_C01,'word' => $word);	
	break;

	case 'price2':
	$res[$m] = array('price' => "$".$op_C02,'word' => $word);
	break;

	case 'price3':
	$res[$m] = array('price' => "$".floor($pric_rate3/3),'word' => $word);	
	break;

	case 'price4':
	$res[$m] = array('price' => "$".floor($pric_rate6/6),'word' => $word);
	break;

	case 'price5':
	$res[$m] = array('price' => "$".floor($pric_rate12/12),'word' => $word);	
	break;

	case 'price6':
	$res[$m] = array('price' => "$".floor($pric_rate24/24),'word' => $word);
	break;

	case 'button':
	$res[$m] = array('buttonword' => $button ,'word' => $word);
	break;

}


}
echo json_encode($res) ;

?>